package com.aloda.orangebank.mapper;

import com.aloda.orangebank.pojo.Admin;
import com.aloda.orangebank.pojo.User;
import org.apache.ibatis.annotations.*;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface SysAdminMapper {
    @Select("select * from admin where username=#{username} and password=#{password}")
    Admin login(Admin admin);

    @Update("update admin set login_time = #{loginTime} where id =#{id}")
    void updateLoginTime(Admin a);

    @Select("select * from orangebank.users")
    List<User> normalTable();

    @Select("select count(*) from orangebank.users")
    int getTotals();

    List<User> list(String username, LocalDateTime begin, LocalDateTime end);

    List<User> listCancel(String username, LocalDateTime begin, LocalDateTime end);

    @Select("select * from users where username=#{username}")
    User getUserByUsername(String username);

    @Delete("delete from orangebank.users where username=#{username}")
    void deleteUserByUsername(String username);

    @Insert("INSERT INTO cancel(username,password,imgUrl,name,phone,mail,create_time,update_time) " +
            "values (#{username},#{password},#{imgUrl},#{name},#{phone},#{mail},#{createTime},#{updateTime})")
    void addCancelledUser(User user);

    @Select("select * from cancel where id=#{id}")
    User getCanceledUserById(Integer id);

    @Insert("INSERT INTO users(username,password,imgUrl,name,phone,mail,create_time,update_time) " +
            "values (#{username},#{password},#{imgUrl},#{name},#{phone},#{mail},#{createTime},#{updateTime})")
    void addRecoverUser(User u);

    @Delete("delete from cancel where id=#{id}")
    void deleteCanceledUserById(Integer id);

    @Delete("delete from cancel where username=#{username}")
    void deleteCanceledUserByUsername(String username);
}
